<template>
	<view class="container">
		<view class="details">
			<view class="form-item border-bottom">
				<view class="title" style="display: flex;">
					<view style="color: red;">*</view>房间号
				</view>
				<input type="text" v-model="homeNum" placeholder="请输入房间号" />
			</view>
			<view class="form-item border-bottom">
				<view class="title" style="display: flex;">
					<view style="color: red;">*</view>手机号
				</view>
				<input type="number" v-model="mobile" placeholder="请输入手机号码" />
			</view>
			<view class="form-item border-bottom">
				<view class="title">联系人</view>
				<input type="text" v-model="name" placeholder="请输入姓名" />
			</view>
		</view>

		<view class="" style="font-size: 26rpx;color: #666;padding: 20rpx 50rpx;" v-if="loginType==2">
			<view class="" style="margin-bottom: 20rpx;">
				温馨提醒：
			</view>
			<view class="" style="margin-bottom: 20rpx;">
				1：请填写您的准确房间号码，非店内顾客请填写 001。
			</view>
			<view class="" style="margin-bottom: 20rpx;">
				2：手机号码及联系人信息请尽量完善，便于订单联络。
			</view>
			<view class="">
				3：如有问题，可返回上一层，一键呼叫前台工作人员。
			</view>
		</view>
		<view class="" style="font-size: 26rpx;color: #666;padding: 20rpx 50rpx;" v-else>
			<view class="" style="margin-bottom: 20rpx;">
				温馨提醒：
			</view>
			<view class="" style="margin-bottom: 20rpx;">
				1：请填写您的准确房间号码，以便我们为您准确送达。
			</view>
			<view class="" style="margin-bottom: 20rpx;">
				2：手机号码及联系人信息请尽量完善，便于订单联络。
			</view>
			<view class="">
				3：如有问题，可返回上一层，一键呼叫前台工作人员。
			</view>
		</view>
		<view class="bottom-menu" @click="submit">提交</view>
		<view class="place"></view>
	</view>
</template>

<script>
	import {
		save,
		getDetail
	} from '@/api/address.js';
	import {
		validatemobile
	} from '@/utils/util.js';
	import regionPicker from '@/components/region-picker/index.vue';
	export default {
		components: {
			regionPicker
		},
		data() {
			return {
				initFlag: true,
				isPopupShow: false,
				region: '',
				selectProvinceId: '',
				selectCityId: '',
				selectAreaId: '',
				details: {},
				id: '',
				name: '',
				mobile: '',
				address: '',
				homeNum: '',
				isDefault: 0,
				loginType: 0
			};
		},
		onLoad(option) {
			this.selectProvinceId = option.selectProvinceId;
			this.selectCityId = option.selectCityId;
			this.selectAreaId = option.selectAreaId;
			this.address = option.address;
			if (option.loginType) {
				this.loginType = option.loginType
			}
			
		//	this.homeNum = uni.getStorageSync("room")
			this.mobile = uni.getStorageSync("mobile")
			this.name = uni.getStorageSync("name")
			this.setTitle(option);
		},
		onShow() {
			if (this.id) {
				this.initFlag = true;
			} else {
				this.initFlag = false;
			}
		},
		methods: {
			submit() {
				// if (!this.name) {
				//     uni.showToast({
				//         title: '请输入姓名！',
				//         icon: 'none',
				//         duration: 2000
				//     });
				//     return;
				// }
				if (this.mobile) {
					if (!validatemobile(this.mobile)) {
						return;
					}
				}

				if (!this.homeNum) {
					uni.showToast({
						title: '请输入房间号！',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				if (!this.mobile) {
					uni.showToast({
						title: '请输入手机号！',
						icon: 'none',
						duration: 2000
					});
					return;
				}
	
			//	uni.setStorageSync("room",this.homeNum)
				uni.setStorageSync("mobile",this.mobile)
				uni.setStorageSync("name",this.name)
				const data = {
					id: this.id,
					name: this.name,
					mobile: this.mobile,
					provinceId: this.selectProvinceId,
					cityId: this.selectCityId,
					districtId: this.selectAreaId,
					address: this.address + this.homeNum,
					isDefault: this.isDefault,
					isTemp: 1
				};
				save(data).then(respanse => {
					uni.navigateBack();
					uni.$emit('getAddress', {
						...respanse.result,
						ifAddressCanPut: 1
					});
				});
			},

			togglePopup() {
				if (this.initFlag) return;
				this.isPopupShow = !this.isPopupShow;
			},
			setTitle(option) {
				let title = '添加地址';
				uni.setNavigationBarTitle({
					title
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.details {
		margin: 20rpx 25rpx;
		background: #ffffff;
		border-radius: 10rpx;
		overflow: hidden;

		.address {
			position: relative;
			display: flex;

			.title {
				padding-left: 27rpx;
				width: 196rpx;
				box-sizing: border-box;
				line-height: 115rpx;
				font-size: 30rpx;
				color: #040000;
			}

			.con {
				flex: 1;
				display: table;
				vertical-align: middle;
				height: 115rpx;
				padding-right: 60rpx;

				.t {
					display: table-cell;
					vertical-align: middle;
					line-height: 40rpx;
					font-size: 30rpx;
					color: #040000;
				}
			}

			&::after {
				left: 27rpx;
				right: 28rpx;
			}

			input {
				position: relative;
				z-index: 3;
				flex: 1;
				display: block;
				padding: 0 28rpx 0 0;
				width: 100%;
				height: 115rpx;
				box-sizing: border-box;
				font-size: 30rpx;
				color: #040000;
				background: none;
			}

			&.select {
				.icon {
					position: absolute;
					right: 28rpx;
					top: 52rpx;
					width: 27rpx;
					height: 15rpx;
				}
			}
		}

		.form-item {
			position: relative;
			height: 115rpx;

			.title {
				position: absolute;
				left: 0;
				top: 0;
				z-index: 2;
				padding-left: 27rpx;
				width: 196rpx;
				box-sizing: border-box;
				line-height: 115rpx;
				font-size: 30rpx;
				color: #040000;
			}

			switch {
				position: absolute;
				right: 0;
				top: 50%;
				transform: translateY(-50%) scale(0.7);
				font-size: 30rpx;
			}

			input {
				position: relative;
				z-index: 3;
				flex: 1;
				display: block;
				padding: 0 28rpx 0 196rpx;
				width: 100%;
				height: 115rpx;
				box-sizing: border-box;
				font-size: 30rpx;
				color: #040000;
				background: none;
			}

			&::after {
				left: 27rpx;
				right: 28rpx;
			}
		}
	}

	.bottom-menu {
		position: fixed;
		left: 25rpx;
		right: 25rpx;
		bottom: 79rpx;
		z-index: 2;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 32rpx;
		color: #fff;
		background: linear-gradient(90deg, #eb7c3f, #ea5d2e);
		border-radius: 45rpx;
	}

	.place {
		height: 169rpx;
		visibility: hidden;
	}
</style>
